package main

import (
	"fmt"
	"os"
)

type DataNode struct {
	cmd     string
	desc    string
	handler func(head *DataNode) //int16
	next    *DataNode
}

// the function called by help command
func help(head *DataNode) {
	fmt.Println("Available commands:")
	for tmp := head; tmp != nil; tmp = tmp.next {
		fmt.Println(tmp.cmd + ":\t" + tmp.desc)
	}
	//return 0
}

// the function called by hello command
func hello(head *DataNode) {
	fmt.Println("Hello! version2.0")
	//return 0
}

// the function called by quit command
func quit(head *DataNode) {
	fmt.Println("GoodBye!")
	//return 1
	os.Exit(3)
}

func searchCmd(head *DataNode, input string) {
	for head != nil {
		if input == head.cmd {
			head.handler(head)
			break
		}
		head = head.next
	}
	if head == nil {
		fmt.Println("Command Not Found, please check again")
	}
}
